package com.zdp.controller;

import com.zdp.common.domain.ResultInfo;
import com.zdp.common.util.ResultInfoUtil;
import com.zdp.pojo.vo.PaymentInfoVO;
import com.zdp.wx.entity.PreOrderResult;
import com.zdp.wx.service.WxOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author sesshomaru
 * @date 2021/8/1 17:34
 */
@RestController
@RequestMapping("payment")
public class PayController {

    @Autowired
    private WxOrderService wxOrderService;

    @GetMapping("test")
    public Object test(String body, String out_trade_no, String total_fee) throws Exception {
        PreOrderResult preOrderResult = wxOrderService.placeOrder(body, out_trade_no, total_fee);
        return preOrderResult;
    }

    @PostMapping("getWXPayQRCode")
    public ResultInfo getWXPayQRCode(String merchantOrderId, String merchantUserId) throws Exception {
        // 支付金额（分）
        String total_fee = "1";
        PreOrderResult preOrderResult = wxOrderService.placeOrder("body", merchantOrderId, total_fee);
        PaymentInfoVO paymentInfoVO = new PaymentInfoVO();
        paymentInfoVO.setAmount(Integer.parseInt(total_fee));
        paymentInfoVO.setMerchantOrderId(merchantOrderId);
        paymentInfoVO.setMerchantUserId(merchantUserId);
        paymentInfoVO.setQrCodeUrl(preOrderResult.getCode_url());
        
        return ResultInfoUtil.buildSuccess(paymentInfoVO);
    }
}
